from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.edge.service import Service  # 修改为 Edge 的 Service

def test_baidu(driver):
    # 访问百度首页
    driver.get("https://www.baidu.com")
    # 等待搜索框元素加载完成
    search_box = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.ID, "kw"))
    )
    # 如果能找到搜索框元素，则表示能访问百度首页
    print("能访问百度首页")

# Specify the path to the EdgeDriver executable
edgedriver_path = "D:\\dev\\edgedriver_win64\\mmsedgedriver.exe"  # 替换为实际的 EdgeDriver 路径
service = Service(edgedriver_path)
driver = webdriver.Edge(service=service)  # 修改为使用 Edge 浏览器

try:
    test_baidu(driver)
except Exception as e:
    print("无法访问百度首页：", str(e))
finally:
    # 关闭浏览器
    driver.quit()

